package cn.edu.nju.software.cdiy.util;

import java.util.Comparator;
import java.util.Date;

import cn.edu.nju.software.cdiy.bean.Hardware;

public class SortByHotAsc implements Comparator {

	@Override
	public int compare(Object o1, Object o2) {
		Hardware h1 = (Hardware) o1;
		Hardware h2 = (Hardware) o2;

		Date now = new Date();

		// this的热度
		long gap = now.getTime() - h1.getInStorageTime().getTime();
		int gapDay = (int) (gap / (24 * 3600 * 1000))+1;

		double nowHot = h1.getSale() / gapDay;

		// 参数的hot
		long oGap = now.getTime() - h2.getInStorageTime().getTime();
		int oGapDay = (int) (oGap / (24 * 3600 * 1000));

		double oHot = h2.getSale() / oGapDay;

		// 升序排列
		if (nowHot > oHot)
			return 1;
		else if (nowHot == oHot)
			return 0;
		else
			return -1;
	}

}
